<?php
// +-------------------------------------------------------------------------+
// | Mobile Melody Plug-in for PHP Melody ( www.phpsugar.com )
// +-------------------------------------------------------------------------+
// | MOBILE MELODY IS NOT FREE SOFTWARE
// | If you have downloaded this software from a website other
// | than www.phpsugar.com or if you have received
// | this software from someone who is not a representative of
// | phpSugar, you are involved in an illegal activity.
// | ---
// | In such case, please contact: support@phpsugar.com.
// +-------------------------------------------------------------------------+
// | Developed by: phpSugar (www.phpsugar.com) / support@phpsugar.com
// | Copyright: (c) 2004-2012 PhpSugar.com. All rights reserved.
// +-------------------------------------------------------------------------+
session_start();
$page_type = 'video';
include('settings.php');

$unique_id = magicSlashes($_GET['vid']);
$video_is_restricted = false;

if ( ! empty($unique_id) && strlen($unique_id) < 10) 
{
	$video = request_video($unique_id);
	$sql = mysql_query("SELECT added FROM pm_videos WHERE uniq_id = '". $unique_id ."'");
	$added_date = mysql_fetch_array($sql);
	
	$category_name = make_cats_mobi('pm_categories', $video['category']);
	$now = time();
	if(strstr($video['category'], ",")) 
	{
		$temp = explode(",", $categories);
		$categories = trim($temp[0]);
	} else {
		$categories = $video['category'];
	}
			
	if ( ! $video_is_restricted && update_view_count_mobi($video['id'])) // @since 1.6.5
	{
		add_to_chart($video['uniq_id']);
	}

	if($video == 0) { 
		header("Location: ". _URL_MOBI ."/index."._FEXT);
		exit;
	}
} else {
		header("Location: ". _URL_MOBI ."/index."._FEXT);
		exit;
}
$comments_no = count_entries('pm_comments', 'uniq_id', $unique_id);

$meta_title = $video['video_title']." - "._SITENAME;
include('header.php');
?>
<div id="video_player">
	<h1><?php echo $video['video_title']; ?></h1>
	<div class="video_details">
	<strong><?php echo $lang['articles_by'] ." ". $video['submitted']; ?></strong> <span class="added_date"><?php echo time_since($added_date[0])." ". $lang['ago']; ?></span> <span class="video_views border2"><?php echo pm_number_format_mobi($video['site_views']); ?> views</span>
	</div>
	<div class="videoWrapper">
<?php
	echo generate_player($video['uniq_id'], "100%", "24%");
?>
	</div>
</div>

<?php echo show_mm_ad("mobile_video"); // ad after the video ?>

<div id="content">
	<?php if(!empty($video['description'])) { ?>
	<div id="video_description">
		<p class="description_txt">
		<?php echo $video['description']; ?>
		</p>
	</div>
	<?php } ?>

	<div id="related_categories">
		<strong><?php echo $lang['related_cats']; ?></strong>: <?php echo $category_name; ?>
	</div>

	<ul class="idTabs"> 
	<li id="btn_blue"><a href="#related"><?php echo $lang['tab_related']; ?></a></li>
	<li id="btn_blue"><a href="#comments"><?php echo $lang['comments']; ?> (<?php echo $comments_no; ?>)</a></li>
	</ul>

	<div id="related">
		<ul id="video_listing">
		<?php
		$sql = mysql_query("SELECT * FROM pm_videos WHERE added <= '". time() ."' AND (category LIKE '%,".$categories.",%' 
				   OR category LIKE '%,".$categories."' 
				   OR category LIKE '".$categories.",%' 
				   OR category='".$categories."') 
				   AND source_id IN (". implode(',', $_mobile_supported_sources) .") 
				   ORDER BY id DESC LIMIT "._RELATED_LIMIT);
		while($row = mysql_fetch_array($sql))
		{
			$video_id = $row['id'];
			echo videoLI($row);
		}
		$num_rows = mysql_num_rows($sql);
		if ($num_rows > 0 && $num_rows >= _RELATED_LIMIT) { 
		?>
		<div id="more<?php echo $video_id; ?>" class="morebox">
		<div class="case" id="browse"></div>
		<div class="extra_data" id="<?php echo $categories; ?>"></div>
		<div align="center">
		<div id="loader"><img src="<?php echo _URL_MOBI; ?>/images/moreajax.gif" /></div>
		<button class="minimal more" id="<?php echo $video_id; ?>">
		<?php translate("Load more videos", lmore_videos); ?>
		</button>
		</div>
		</div>
		<?php } ?>

		</ul>
	</div>
	
	<div id="comments">
		<div class="post_comment">
		<?php
		if($logged_in == 1) {
		?>		
			<span class="mycommentspan" name="mycommentspan" id="mycommentspan"></span>
			<?php

			?>
			<form name="myform" method="post" id="myform" action="">
			<label for="comment_txt"><?php echo $lang['post_comment']; ?></label>
			<input name="comment_txt" id="c_comment_txt" type="text" size="10" value="" />
			<input type="hidden" id="c_vid" name="vid" value="<?php echo $video['uniq_id']; ?>" />
			<input type="hidden" id="c_user_id" name="user_id" value="<?php echo $userdata['id']; ?>" />
			<button class="submit border2" id="c_submit"><?php echo $lang['submit_comment']; ?></button>
			</form>
		<?php 
		} else { 
			translate('<a href="'._URL_MOBI.'/login.'._FEXT.'">Sign in</a> with your <strong>'._SITENAME.'</strong> account to post comments.', lmore_signin2post); 
		}
		?>
		</div>

		<ul id="video_comments">
<?php
#echo show_comments_mobi($unique_id, $userdata['power']);
?>
		<?php
		$sql = mysql_query("SELECT * FROM pm_comments WHERE uniq_id = '". $unique_id ."' AND approved = '1' ORDER BY id DESC LIMIT "._COMMENTS_LIMIT);
		while($row = mysql_fetch_array($sql))
		{
		$comment_id = $row['id'];
		?>
			<li>
			<img src="<?php echo getavatar($row['user_id'], $row['username']); ?>" border="0" class="comm_avatar border4" />
			<div class="comment">
				<span class="comm_name"><?php echo $row['username']; ?></span><span class="comm_date"><?php echo time_since($row['added'])." ".$lang['ago']; ?></span>
				<div class="comm_txt"><?php echo htmlentities($row['comment'], ENT_COMPAT, 'UTF-8'); ?></div>
			</div>
			</li>
		<?php
		}
		if(mysql_num_rows($sql) > 0 && mysql_num_rows($sql) >= _COMMENTS_LIMIT) { 
		?>
		<div id="morec<?php echo $comment_id; ?>" class="morecbox">
		<div class="case" id="video_comments"></div>
		<div class="extra_data" id="<?php echo $unique_id; ?>"></div>
		<div align="center">
		<div id="loader"><img src="<?php echo _URL_MOBI; ?>/images/moreajax.gif" /></div>
		<button class="minimal morec" id="<?php echo $comment_id; ?>">
		<?php translate("Load more comments", lmore_comments); ?>
		</button>
		</div>
		</div>
		<?php
		} else {
		?>
		
		<?php
		}
		?>
		</ul><!--end comments-->
	</div>
<?php
include('footer.php');
?>